﻿/*
/// 
/// Portions Copyright 1999-2004 Carnegie Mellon University.  
/// Portions Copyright 2004 Sun Microsystems, Inc.  
/// Portions Copyright 2004 Mitsubishi Electric Research Laboratories.
/// All Rights Reserved.  Use is subject to license terms.
/// 
/// See the file "license.terms" for information on usage and
/// redistribution of this file, and for a DISCLAIMER OF ALL 
/// WARRANTIES.
 *
 */

using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util.Props;


namespace Decoder
{
    public class Decoder: AbstractDecoder
    {
        public Decoder() 
        {
            // Keep this or else XML configuration fails.
        }

        /** The property for the number of features to recognize at once. */
        [S4Integer(defaultValue = 100000)]
        public static String PROP_FEATURE_BLOCK_SIZE = "featureBlockSize";
        private int featureBlockSize;

     
        override public void newProperties(PropertySheet ps)
        {
            featureBlockSize = ps.getInt(PROP_FEATURE_BLOCK_SIZE);
        }

        /// <summary>
        /// Decode frames until recognition is complete.
        /// </summary>
        /// <param name="referenceText">referenceText the reference text (or null)</param>
        /// <returns>a result</returns>
        public override IResult decode(String referenceText)
        {
            searchManager.startRecognition();
            IResult result;
            do
            {
                result = searchManager.recognize(featureBlockSize);
                if (result != null)
                {
                    result.setReferenceText(referenceText);
                    fireResultListeners(result);
                }
            } while (result != null && !result.isFinal());
            searchManager.stopRecognition();
            return result;
        }
    }
}
